package org.cglib.example2;

import net.sf.cglib.core.DebuggingClassWriter;

/**
 * https://www.cnblogs.com/lvbinbin2yujie/p/10284316.html
 * 研究 MethodProxy类中 invoke 和 invokeSuper 方法区别
 * invoke调用原始类对象(未增强),invokeSuper调用增强类
 * invokeSuper方法调用的对象已经是增强类
 * ,所以会再走一遍 MyMethodInterceptor的 interceptor方法,如果是个拦截器链条,就会重新在走一次拦截器链
 *
    Invoke the original (super) method on the specified object.
            obj – the enhanced object(必须是增强类的实例), must be the object passed as the first argument to the MethodInterceptor
            args – the arguments passed to the intercepted method; you may substitute a different argument array as long as the types are compatible
     invokeSuper(Object obj, Object[] args)


    Invoke the original method, on a different object of the same type.
            obj – the compatible object( 兼容类的实例 ); recursion will result if you use the object passed as the first argument to the MethodInterceptor (usually not what you want)
            args – the arguments passed to the intercepted method; you may substitute a different argument array as long as the types are compatible
    proxy.invoke(obj, args);

 */
public class AppTestCglib {

    public static void main(String[] args) {

        String classesDir = System.getProperty("user.dir") +"/cglibTest/target/cglibGenClasses4Example2/";
        System.setProperty(DebuggingClassWriter.DEBUG_LOCATION_PROPERTY, classesDir);

        Target enhancedInstance =(Target) new MyMethodInterceptor(new Target()).getEnhancedInstance();
        System.out.println("444");

        String aReturn = enhancedInstance.a();

        System.out.println("结果是:"+aReturn);
        System.out.println("enhancedInstance:"+enhancedInstance.getClass());
    }
}